package com.fht.service.member.impl;

import com.fht.entity.MemberCategory;
import com.fht.mapper.member.MemberCategoryMapper;
import com.fht.service.member.MemberCategoryService;
import com.fht.vo.LayUITableVO;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import tk.mybatis.mapper.entity.Example;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Slf4j
@Service
public class MemberCategoryServiceImpl implements MemberCategoryService {

    @Resource
    public MemberCategoryMapper memberCategoryMapper;

    @Override
    public List<MemberCategory> selectAll() {
        return memberCategoryMapper.selectAll();
    }

    @Override
    public LayUITableVO<List<MemberCategory>> findPage(Map<String, Object> map) {
        PageHelper.startPage((int) map.get("page"),(int) map.get("limit"));

        List<MemberCategory> list = memberCategoryMapper.selectAll();

        PageInfo<MemberCategory> pageInfo = new PageInfo<>(list);

        LayUITableVO<List<MemberCategory>> vo = new LayUITableVO<>();
        vo.setCount(pageInfo.getTotal());
        vo.setData(pageInfo.getList());

        return vo;
    }

    @Override
    public MemberCategory selectById(String id) {
        return memberCategoryMapper.selectByPrimaryKey(id);
    }

    @Override
    @Transactional
    public void update(MemberCategory memberCategory) {
        memberCategoryMapper.updateByPrimaryKeySelective(memberCategory);
    }

    @Override
    @Transactional
    public void save(MemberCategory memberCategory) {
        memberCategoryMapper.insertSelective(memberCategory);
    }

    @Override
    @Transactional
    public void deleteById(String id) {
        memberCategoryMapper.deleteByPrimaryKey(id);
    }
}
